import {
  changeGroupBtnsStatusAction, changeGroupBtnsShowAction, changeGroupBtnsUpateAction, GroupDeleteValueAction, GroupDataAction,
  ChangeGroupParentOffAction, ChageIdAction, GroupOffAction, checkedKeysAction, ChangeCheckedOff, ChangeMembers, ChangeLeaders, ChangeMembersUser
} from './_action';

const stateData = {
  GroupBtnsStatus: true,
  GroupBtnsShowStatus: true,
  GroupBtnsUpate: false,
  GroupDeleteValue: false,
  GroupData: {
    code: '',
    description: '',
    groupType: '',
    id: '',
    parentId: '',
    path: '',
    name: ''
  },
  ID: '',
  GroupOff: false,
  checkedKeys: [],
  checkedOff: true,
  GroupMembersUser: [],
  GroupMembers: [],
  GroupLeaders: []
};

export function getGroup(state = stateData, action) {
  switch (action.type) {
    case 'changeGroupBtnsStatus':
      var newState = JSON.parse(JSON.stringify(state));
      newState.GroupBtnsStatus = action.GroupBtnsStatus;
      return newState;
    case 'changeGroupBtnsShow':
      var newState = JSON.parse(JSON.stringify(state));
      newState.GroupBtnsShowStatus = action.GroupBtnsShowStatus;
      return newState;
    case 'changeGroupBtnsUpate':
      var newState = JSON.parse(JSON.stringify(state));
      newState.GroupBtnsUpate = action.GroupBtnsUpate;
      return newState;
    case 'GroupDeleteValue':
      var newState = JSON.parse(JSON.stringify(state));
      newState.GroupDeleteValue = action.GroupDeleteValue;
      return newState;
    case 'ChangeGroupParentOff':
      var newState = JSON.parse(JSON.stringify(state));
      newState.GroupParentOff = action.GroupParentOff;
      return newState;
    case 'GroupData':
      var newState = JSON.parse(JSON.stringify(state));
      newState.GroupData = action.GroupData;
      return newState;
    case 'ChangeID':
      var newState = JSON.parse(JSON.stringify(state));
      newState.ID = action.ChangeID;
      return newState;
    case 'GroupOff':
      var newState = JSON.parse(JSON.stringify(state));
      newState.GroupOff = action.GroupOff;
      return newState;
    case 'ChangeCheckedKeys':
      var newState = JSON.parse(JSON.stringify(state));
      newState.checkedKeys = action.checkedKeys;
      return newState;
    case 'ChangeCheckedOff':
      var newState = JSON.parse(JSON.stringify(state));
      newState.checkedOff = action.checkedOff;
      return newState;
    case 'ChangeMembers':
      var newState = JSON.parse(JSON.stringify(state));
      newState.GroupMembers = action.GroupMembers;
      return newState;
    case 'ChangeLeaders':
      var newState = JSON.parse(JSON.stringify(state));
      var oData = [];
      action.GroupLeaders.forEach(item => {
        oData.push(item.id);
      });
      newState.GroupLeaders = oData;
      return newState;
    case 'ChangeMembersUser':
      var newState = JSON.parse(JSON.stringify(state));
      var oData = [];
      action.GroupMembersUser.forEach(item => {
        oData.push(item.name);
      });
      newState.GroupMembersUser = oData;
      return newState;
    default:
      return state;
  }
}


// export default setCounter;

